﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;


namespace TMS
{
    public partial class Products : Form
    {
        public MySqlDataAdapter MyDA = new MySqlDataAdapter();

        public Products()
        {
            InitializeComponent();          
        }

        private void Products_Load(object sender, EventArgs e)
        {
            //string connString = @"server=localhost;userid=root;password=pass;database=mydb";
            string connString = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;

            MySqlConnection mysqlCon = new MySqlConnection(connString);
            mysqlCon.Open();


            string sqlSelectAll = "SELECT * from Products";
            MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, mysqlCon);

            DataTable table = new DataTable();
            MyDA.Fill(table);

            BindingSource bSource = new BindingSource();
            bSource.DataSource = table;

            UsersDataGridView.DataSource = bSource;
            mysqlCon.Close();
        }

        private void UpdateButton_Click(object sender, EventArgs e)
        {
            //string connString = @"server=localhost;userid=root;password=pass;database=mydb";
            string connString = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;

            MySqlConnection mysqlCon = new MySqlConnection(connString);
            mysqlCon.Open();


            string sqlSelectAll = "SELECT * from Products";
            MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, mysqlCon);

            DataTable table = new DataTable();
            MyDA.Fill(table);

            BindingSource bSource = new BindingSource();
            bSource.DataSource = table;

            UsersDataGridView.DataSource = bSource;
            mysqlCon.Close();

        }

        private void UsersDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void NewProduct_Click(object sender, EventArgs e)
        {
            NewProduct frm = new NewProduct();
            this.Hide();
            frm.ShowDialog();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
